#define  _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n == 0 || n == 1)
    {
        cout << 0;
        return 0;
    }
    int dp[100000];
    dp[0] = 0;
    dp[1] = 1;
    int ret = 1e5;
    for (int i = 2; ; i++)
    {
        dp[i] = dp[i - 1] + dp[i - 2];
        if (dp[i] <= n)
            ret = n - dp[i];
        else
            break;
    }
    cout << ret;
    return 0;
}